<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>誉禾植物店</title>
  <!-- bootstrap样式 -->
  <link href="https://cdn.staticfile.net/twitter-bootstrap/5.1.1/css/bootstrap.min.css" rel="stylesheet">
  <!-- element-ui的样式 -->
  <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">

  <!-- vue2框架的js和emenet-ui的js -->
  <script src="https://unpkg.com/vue@2/dist/vue.js"></script>
  <script src="https://unpkg.com/element-ui/lib/index.js"></script>
  <!-- 可以发送jquery请求 -->
  <script src="../js/jquery.min.js"></script>
  <!-- bootstrap框架 -->
  <script src="https://cdn.staticfile.net/twitter-bootstrap/5.1.1/js/bootstrap.bundle.min.js"></script>
  <!-- js动画 -->
  <script src="https://cdn.jsdelivr.net/npm/gsap@3.12.5/dist/gsap.min.js"></script>
  <!-- 用于发送请求 -->
  <script src="https://cdn.staticfile.org/vue-resource/1.5.1/vue-resource.min.js"></script>
  <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<!-- 登录 -->
<style>
  @media (min-width: 1200px) {

    .container,
    .container-lg,
    .container-md,
    .container-sm,
    .container-xl {
      max-width: 1200px;
    }
  }

  * {
    padding: 0;
    margin: 0;
    box-sizing: border-box;
  }

  input {
    border: 1px solid #8eb359;
    outline: none;
    font-size: 14px;
    color: #5a5a5a;
    padding-left: 10px;
  }

  button {
    border: 0;
    padding: 10px 20px;
    background-color: #8eb359;
    color: #fff;
  }
</style>

<body>
  <div id="login">
    <!-- 网页头部 -->
    <header>
      <iframe src="./header.html" height="110px" width="100%" frameborder="0"></iframe>
    </header>
    <!-- 登录 -->
    <section style="margin: 3% 0;">
      <div class="container">
        <div style="display: flex;">
          <div style="width: 50%;">
            <img src="../img/login_bg1.jpg" width="100%" alt="">
          </div>
          <div style="margin: auto; width: 50%;text-align: center;">
            <h4 style="font-weight: 600;">用户登录</h4>
            <div style="margin-top: 3%;">
              <label for="account">账号：</label>
              <input type="text" v-model="ruleFrom.account" style="height: 40px; width: 70%;" placeholder="请输入您的账号">
            </div>
            <div style="margin-top: 3%;">
              <label for="password">密码：</label>
              <input type="password" style="height: 40px; width: 70%;" v-model="ruleFrom.password"
                placeholder="请输入您的密码">
            </div>
            <div style="margin-top: 3%;">
              <button @click="login()">登录</button>
              <p style="font-size: 14px;margin-top: 2%;">还没有账号？立即<a style="color: #8eb359;"
                  href="./register.html">注册</a></p>
            </div>
          </div>
        </div>
      </div>
    </section>
  </div>
</body>
<script>
  new Vue({
    el: '#login',
    data() {
      return {
        ruleFrom: {}
      }
    },
    created() {
      // 进入登录页面的时候进行一下清除数据
      localStorage.removeItem("userId");
    },
    methods: {
      // 登录
      async login() {
        if (this.ruleFrom.password == "") {
          this.$message.error("请输入密码");
          return;
        }
        const { data: result } = await this.$http.post("http://localhost:9081/plants_user/login", this.ruleFrom);
        console.log(result);
        if (result.flag) {
          // 存入用户id
          localStorage.setItem("userId", result.message);
          // 跳转首页
          window.location.href = './home.html';
        } else {
          this.$message.error(result.message);
        }
      }
    }
  })
</script>

</html>